$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        id:null,
        init:function () {
            this.form = new xhForm($('#xh_form'));
            this.form.parse();
            this.id  = xhTool.getQuery('id');
            this.form.bindRequired($("#bt_modal_confirm", parent.document));
            this.listener();
        },
        listener:function () {
            var $this = this;
            //日期
            $('[name=day]').change(function () {
                $this.funObj().changeData($(this).val());
            });

            //确定
            $("#bt_modal_confirm", parent.document).click(function () {
                $this.funObj().submitForm();
            });
        },
        funObj:function () {
            var $this = this;
            return {
                changeData:function (num) {
                    num = parseInt(num);
                    if (num >= 30) {
                        $('[name=day]').val(30);
                    } else  if (num <= 0) {
                        $('[name=day]').val(1);
                    } else  {
                        $('[name=day]').val(num);
                    }

                },
                submitForm:function () {
                    var reason = $this.funObj().getReason();
                    var day    = $('[name=day]').val();
                    if (day <= 0 || day > 30) {
                        sendErrorMsg('错误', '禁言日期在1-30天之内');
                        return false;
                    }
                    xhExtra.ajaxRequest('feedback/shieldUser', {id:$this.id,reason:reason,shieldDate:day},{},function (res) {
                        window.top.xhTop.showSuccess(res.msg);
                        if (xhTool.getQuery('needReload') == 'true') {
                            window.top.xhTop.getActiveFrame().obj.dataGrid.reload();
                        }
                        window.top.xhTop.getActiveFrame().obj.frame[0].contentWindow.location.reload();
                        window.top.xhTop.closeModal();
                    });
                },
                getReason:function () {
                    var index = $('#reasonSelect').val();
                    if (index != 0) {
                        return $("#reasonSelect option:selected").text();
                    }
                    return $('#otherReason').val();
                }
                
            }
        }
    }
};
